package com.example.testapp.data.entity

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Index
import java.time.LocalDateTime

/**
 * 余额账单表
 */
@Entity(
    tableName = "balance",
    indices = [
        Index(name = "idx_balance_bill_date", value = ["bill_date"]),
        Index(name = "idx_balance_type", value = ["type"]),
        Index(name = "idx_balance_status", value = ["status"]),
        Index(name = "idx_balance_del_flag", value = ["del_flag"])
    ]
)
class Balance : BaseEntity() {
    /**
     * 金额，单位分
     */
    @JvmField
    @ColumnInfo(name = "amount")
    var amount: Int? = null

    /**
     * 类别名称
     */
    @JvmField
    @ColumnInfo(name = "category_name")
    var categoryName: String? = null

    /**
     * 图标类型
     */
    @JvmField
    @ColumnInfo(name = "icon_type")
    var iconType: String? = null

    /**
     * 账单类型（1-支出，2-收入）
     */
    @JvmField
    @ColumnInfo(name = "type")
    var type: Int? = null

    /**
     * 描述/备注
     */
    @JvmField
    @ColumnInfo(name = "description")
    var description: String? = null

    /**
     * 账单日期
     */
    @JvmField
    @ColumnInfo(name = "bill_date")
    var billDate: LocalDateTime? = null

    /**
     * 处理状态（1-待处理，2-处理中，3-已完成，4-失败）
     */
    @JvmField
    @ColumnInfo(name = "status")
    var status: Int? = null

    /**
     * 支付方式
     */
    @JvmField
    @ColumnInfo(name = "payment_method")
    var paymentMethod: String? = null

    /**
     * 消费地点（可选）
     */
    @JvmField
    @ColumnInfo(name = "location")
    var location: String? = null

    /**
     * 标签，多个标签用逗号分隔
     */
    @JvmField
    @ColumnInfo(name = "tags")
    var tags: String? = null

    // Getter和Setter方法，用于Java代码兼容性
    fun getAmount(): Int? = amount
    fun setAmount(amount: Int?) { this.amount = amount }

    fun getCategoryName(): String? = categoryName
    fun setCategoryName(categoryName: String?) { this.categoryName = categoryName }

    fun getIconType(): String? = iconType
    fun setIconType(iconType: String?) { this.iconType = iconType }

    fun getType(): Int? = type
    fun setType(type: Int?) { this.type = type }

    fun getDescription(): String? = description
    fun setDescription(description: String?) { this.description = description }

    fun getBillDate(): LocalDateTime? = billDate
    fun setBillDate(billDate: LocalDateTime?) { this.billDate = billDate }

    fun getStatus(): Int? = status
    fun setStatus(status: Int?) { this.status = status }

    fun getPaymentMethod(): String? = paymentMethod
    fun setPaymentMethod(paymentMethod: String?) { this.paymentMethod = paymentMethod }

    fun getLocation(): String? = location
    fun setLocation(location: String?) { this.location = location }

    fun getTags(): String? = tags
    fun setTags(tags: String?) { this.tags = tags }

    // 从BaseEntity继承的字段的Getter和Setter
    fun getId(): Long = id
    fun setId(id: Long) { this.id = id }

    fun getCreateDate(): LocalDateTime? = createDate
    fun setCreateDate(createDate: LocalDateTime?) { this.createDate = createDate }

    fun getUpdateDate(): LocalDateTime? = updateDate
    fun setUpdateDate(updateDate: LocalDateTime?) { this.updateDate = updateDate }

    fun getDelAt(): LocalDateTime? = delAt
    fun setDelAt(delAt: LocalDateTime?) { this.delAt = delAt }

    fun getDelFlag(): Int? = delFlag
    fun setDelFlag(delFlag: Int?) { this.delFlag = delFlag }
    fun setDelFlag(delFlag: Byte) { this.delFlag = delFlag.toInt() }

    companion object {
        /**
         * 处理状态：待处理
         */
        const val STATUS_PENDING = 1
        
        /**
         * 处理状态：处理中
         */
        const val STATUS_PROCESSING = 2
        
        /**
         * 处理状态：已完成
         */
        const val STATUS_COMPLETED = 3
        
        /**
         * 处理状态：失败
         */
        const val STATUS_FAILED = 4
        
        /**
         * 账单类型：支出
         */
        const val TYPE_EXPENSE = 1
        
        /**
         * 账单类型：收入
         */
        const val TYPE_INCOME = 2
    }
} 